#ifndef __XGU_MEMBERFUNCTOR02_H__
#define __XGU_MEMBERFUNCTOR02_H__

#include "Functor.h"

namespace xgu
{
	// ------------------------------------------------------------------------
	// 2 Arguments
	template <typename TClass, typename TRet, typename TArg1, typename TArg2>
	class MemberFunctor<TClass, TRet, TArg1, TArg2> : public Functor<TRet, TArg1, TArg2>
	{
	public:
		typedef TRet (TClass::*Func)(TArg1, TArg2);

		MemberFunctor(TClass& C, Func F) : c(C), f(F)
		{}

		virtual TRet operator() (TArg1 a1, TArg2 a2)
		{ return (c.*f)(a1, a2); }

		virtual bool operator== (const Functor<TRet, TArg1, TArg2>& rhs) const
		{
			if (&rhs == this)
				return true;
			else
			{
				const MemberFunctor<TClass, TRet, TArg1, TArg2>* mf = 
					dynamic_cast<const MemberFunctor<TClass, TRet, TArg1, TArg2>*>(&rhs);
				if (mf)
				{
					return &(mf->c) == &c && mf->f == f;
				}
			}
			return false;
		}

		virtual Functor<TRet, TArg1, TArg2>* Clone() const
		{
			return new MemberFunctor(c, f);
		}

	private:
		TClass& c;
		Func f;
	};

}

#endif